//
//  LBImageGrabber.m
//  look.book
//
//  Created by Chih Yuan Liu on 3/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "LBImageGrabber.h"


@implementation LBImageGrabber

-(id)initWithImageView:(UIImageView*)imageview indicator:(UIActivityIndicatorView*) indicator 
             thumImage:(UIImageView*)thumbImageview thumbIndicator:(UIActivityIndicatorView*) thumbIndicator
{
	if((self = [super init])){
		holder = imageview;
		spinner = indicator;
        thumbHolder = thumbImageview;
        thumbSpinner = thumbIndicator;
        fetcher = [[LBImageFetcher alloc] init];
	}
	return self;
}

-(void) grabImage:(NSString*) url{
	fetcher.delegate = self;
	[fetcher getDataFromLB:url];
}

- (void)fetcherBegin:(LBImageFetcher*)sender{}
- (void)fetcherEnd:(LBImageFetcher*)sender{
    [sender release];
}
- (void)fetcherSucceeded:(LBImageFetcher*)sender data:(NSData*)data{
	UIImage *image = [UIImage imageWithData:data];
	if(holder!=nil){
		[holder setImage:image];
        [thumbHolder setImage:image];
		[spinner stopAnimating];
        [thumbSpinner stopAnimating];
	}
    
}
- (void)fetcherFailed:(LBImageFetcher*)sender{}

- (void) dealloc {  
    [fetcher release];
    [super dealloc]; 
}

@end
